package com.beyond.trace.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.beyond.trace.domain.BusinessManager;
import com.beyond.trace.service.BusinessManagerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Objects;

/**
 * @ClassName: BusinessManagerController
 * @author: z越
 * @date: 2024/4/15  14:36
 * @description
 */
@RestController
@RequestMapping("/screen/business/manager")
@Api(tags = "招商引资专栏")
@RequiredArgsConstructor
public class BusinessManagerController extends BaseController {
    private final BusinessManagerService businessManagerService;
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public TableDataInfo page(){
        startPage();
        return getDataTable(this.businessManagerService.list());
    }
    @PostMapping("/add")
    @ApiOperation("新增")
    public AjaxResult add(@RequestBody BusinessManager businessManager){
        businessManager.setCreateTime(new Date());
        return AjaxResult.success(this.businessManagerService.save(businessManager));
    }

    @PutMapping
    @ApiOperation("修改")
    public AjaxResult update(@RequestBody BusinessManager businessManager){
        if (Objects.isNull(businessManager.getId())){
            return AjaxResult.error("id不能为空");
        }
        return AjaxResult.success(this.businessManagerService.updateById(businessManager));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public AjaxResult delete(@PathVariable Long id){
        return AjaxResult.success(this.businessManagerService.removeById(id));
    }

    @GetMapping("/list")
    @ApiOperation("查询全部(不分页)")
    @ApiImplicitParam(name = "type",value = "类型",dataType = "String",dataTypeClass = String.class)
    public AjaxResult getByType(String type){
        LambdaQueryWrapper<BusinessManager> wrapper = new LambdaQueryWrapper<BusinessManager>();
        if (StringUtils.isNotEmpty(type)){
            wrapper.eq(BusinessManager::getType,type);
        }
        wrapper.orderByDesc(BusinessManager::getCreateTime);
        return AjaxResult.success(this.businessManagerService.list(wrapper));
    }
}
